// 不含 x 的数
// https://soj.turingedu.cn/problem/51200/
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
using T = ll;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 20;

int n, x;
int dgt[maxn];
ll f[maxn];

ll dp(int i, bool lmt = 1) {
    if (i == 0) return 1;
    if (!lmt && f[i]) return f[i];
    ll ret = 0;
    for (int j = 0, ed = lmt ? dgt[i] : 9; j <= ed; ++j) {
        if (j == x) continue;
        ret += dp(i - 1, lmt && j == ed);
    }
    if (!lmt) f[i] = ret;
    return ret;
}

ll pre(ll num) {
    if (num == 0) return 1;
    n = 0;
    if (num == 0) dgt[++n] = 0;
    while (num > 0) dgt[++n] = num % 10, num /= 10;
    return dp(n);
}

int main() {
    ll l = rad(), r = rad();
    x = rad();
    cout << pre(r) - pre(l - 1);
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}